//
//  JARetweetedStatusView.swift
//  JAWeiBo
//
//  Created by Arvin on 17/4/6.
//  Copyright © 2017年 Arvin. All rights reserved.
//

import UIKit

class JARetweetedStatusView: UIView {
    
    ///视图模型
    var statusViewModel: JAStatusViewModel? {
        didSet {
            retweetedStatusLabel.text = statusViewModel?.statusModel.retweeted_status?.text
            
             pictureView.statusViewModel = statusViewModel
            
            //判断是否有配图.有就显示,无就不显示
            //有配图
            if let count = statusViewModel?.statusModel.retweeted_status?.pic_urls?.count, count > 0 {
                pictureView.snp.updateConstraints({ (make) in
                    make.top.equalTo(retweetedStatusLabel.snp.bottom).offset(10)
                    make.size.equalTo(statusViewModel!.pictureViewSize)
                 
                })
                
            }
            else { //无配图,将配图调整到看不见为止
                
                pictureView.snp.updateConstraints({ (make) in
                    make.top.equalTo(retweetedStatusLabel.snp.bottom)
                    make.size.equalTo(CGSize.zero)

                })
                
            }
        

        }
    }
    

    ///添加微博正文的label
    lazy var retweetedStatusLabel: FFLabel = FFLabel(title: nil)
    
    ///配图视图
    let pictureView: JAStatusPictureView = JAStatusPictureView()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

extension JARetweetedStatusView {
    func setupUI () {
        
        //添加子视图
        addSubview(retweetedStatusLabel)
        addSubview(pictureView)
        
        //添加约束
        retweetedStatusLabel.snp.makeConstraints { (make) in
            make.top.left.equalTo(self).offset(10)
            make.right.equalTo(self).offset(-10)
        }
        
        pictureView.snp.makeConstraints { (make) in
            make.top.equalTo(retweetedStatusLabel.snp.bottom).offset(10)
            make.left.equalTo(retweetedStatusLabel)
            make.bottom.equalTo(self).offset(-10)
            make.size.equalTo(CGSize.zero)
        }
    }
}
